load("//tools/lint:lint.bzl", "add_lint_tests")
load(
    "//tools/skylark:drake_cc.bzl",
    "drake_cc_googletest",
    "drake_cc_library",
    "drake_cc_package_library",
)

package(default_visibility = ["//visibility:public"])

filegroup(
    name = "doxygen_input",
    srcs = ["yaml_doxygen.h"],
    tags = ["nolint"],
    visibility = ["//doc/doxygen_cxx:__pkg__"],
)

drake_cc_package_library(
    name = "yaml",
    visibility = ["//visibility:public"],
    deps = [
        ":yaml_io",
        ":yaml_io_options",
        ":yaml_node",
        ":yaml_read_archive",
        ":yaml_write_archive",
    ],
)

drake_cc_library(
    name = "yaml_io_options",
    srcs = ["yaml_io_options.cc"],
    hdrs = ["yaml_io_options.h"],
    deps = [
        "//common:essential",
    ],
)

drake_cc_library(
    name = "yaml_node",
    srcs = ["yaml_node.cc"],
    hdrs = ["yaml_node.h"],
    deps = [
        "//common:essential",
        "//common:overloaded",
        "//common:string_container",
    ],
)

drake_cc_library(
    name = "yaml_read_archive",
    srcs = ["yaml_read_archive.cc"],
    hdrs = ["yaml_read_archive.h"],
    deps = [
        ":yaml_io_options",
        ":yaml_node",
        "//common:essential",
        "//common:name_value",
        "//common:nice_type_name",
        "//common:unused",
        "@yaml_cpp_internal//:yaml_cpp",
    ],
)

drake_cc_library(
    name = "yaml_write_archive",
    srcs = ["yaml_write_archive.cc"],
    hdrs = ["yaml_write_archive.h"],
    deps = [
        ":yaml_node",
        "//common:essential",
        "//common:name_value",
        "//common:nice_type_name",
        "//common:overloaded",
        "//common:unused",
        "@yaml_cpp_internal//:yaml_cpp",
    ],
)

drake_cc_library(
    name = "yaml_io",
    srcs = ["yaml_io.cc"],
    hdrs = ["yaml_io.h"],
    deps = [
        ":yaml_io_options",
        ":yaml_read_archive",
        ":yaml_write_archive",
    ],
)

# === test/ ===

drake_cc_library(
    name = "example_structs",
    testonly = True,
    hdrs = ["test/example_structs.h"],
    visibility = ["//visibility:private"],
    deps = [
        "//common:name_value",
    ],
)

drake_cc_googletest(
    name = "json_test",
    deps = [
        ":example_structs",
        ":yaml_io",
        "//common:temp_directory",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "yaml_doxygen_test",
    deps = [
        ":yaml_io",
        "//common:find_resource",
        "//common:temp_directory",
    ],
)

drake_cc_googletest(
    name = "yaml_io_test",
    data = [
        "test/yaml_io_test_input_1.yaml",
        "test/yaml_io_test_input_2.yaml",
    ],
    deps = [
        ":example_structs",
        ":yaml_io",
        "//common:find_resource",
        "//common:temp_directory",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "yaml_node_test",
    deps = [
        ":yaml_node",
        "//common/test_utilities:expect_throws_message",
        "//common/test_utilities:limit_malloc",
    ],
)

drake_cc_googletest(
    name = "yaml_performance_test",
    deps = [
        ":yaml_io",
        ":yaml_read_archive",
        "//common:autodiff",
        "//common:name_value",
        "//common/test_utilities:limit_malloc",
    ],
)

drake_cc_googletest(
    name = "yaml_read_archive_test",
    deps = [
        ":example_structs",
        ":yaml_read_archive",
        "//common:name_value",
        "//common/test_utilities:eigen_matrix_compare",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "yaml_write_archive_test",
    deps = [
        ":example_structs",
        ":yaml_write_archive",
        "//common:name_value",
        "//common/test_utilities:expect_throws_message",
    ],
)

drake_cc_googletest(
    name = "yaml_write_archive_defaults_test",
    deps = [
        ":example_structs",
        ":yaml_write_archive",
    ],
)

add_lint_tests()
